import { merge, extend } from './utils'
import Request from './core/request'
import defaults from './defaults'
import bind from './helpers/bind'
// import CancelToken from './core/cancelToken'
// import graphQL from './core/graphQL'

function createInstance(config) {
	const context = new Request(config)
  // const instance = Request.prototype.request.bind(context)
  const instance = bind(Request.prototype.request, context)
  extend(instance, Request.prototype, context)
	extend(instance, context)
	return instance
}

const request = createInstance(defaults)

request.create = function (config) {
	return createInstance(merge(defaults, config))
}

// request.CancelToken = CancelToken
// request.graphQL = graphQL

export default request